package it.polimi.traveldream.web.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import it.polimi.traveldream.ejb.management.HotelDTO;
import it.polimi.traveldream.ejb.management.HotelMgr;

@ManagedBean(name = "hotelBean")
@RequestScoped
public class BeanHotel {

	@EJB
	private HotelMgr hotelMgr;
	
	private HotelDTO hotel = new HotelDTO();
	
	private HotelDTO selected;
	
	public HotelDTO getHotel() {
		return hotel;
	}
	
	public void setHotel(HotelDTO hotel) {
		this.hotel = hotel;
	}
	
	public List<HotelDTO> getListaHotel() {
		return hotelMgr.getHotels();
	}
	
	public String creaHotel() {
		hotelMgr.save(hotel);
		return "/pagine_impiegati/prodottoOk?faces-redirect=true";
		
		
	}
	
	public String cancella(){
		hotelMgr.elimina(hotel);
		return "/pagine_impiegati/gestioneHotel?faces-redirect=true";
	}
	
	public void confirmDel(){
		if (hotel.getIdHotel() != 0) {
			cancella();
			FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cancellazione completata",  "");  

			FacesContext.getCurrentInstance().addMessage(null, message);
		}
	}

	public HotelDTO getSelected() {
		return selected;
	}

	public void setSelected(HotelDTO selected) {
		this.selected = selected;
	}
	
	public HotelDTO getHotelId(int id) {
		return hotelMgr.cercaById(id);
	}

}
